<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>经手人</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<form class="layui-form" action="javascript:;"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
    <div class="layui-form-item">
        <label class="layui-form-label">部门名称</label>
        <div class="layui-input-inline">
            <input type="text" name="deptName" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="allName" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="*">查询</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<table id="demo" lay-filter="test"></table>
<div>
    <button class="layui-btn" id="queding">确定</button>
    <button class="layui-btn layui-btn-danger" id="quxiao">取消</button>
</div>


    <script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
    <script src="../../common/common.js"></script>
    <script>
        layui.use(['table','form'], function(){
            var table = layui.table;
            var form  = layui.form;

            var checkdata;
            var checktype;
            table.on('radio(test)', function(obj){ //test 是 table 标签对应的 lay-filter 属性

                console.log(obj.checked); //当前是否选中状态
                console.log(obj.data); //选中行的相关数据
                checkdata = obj.data;
                checktype = obj.checked;
            });

            // 确定按钮的监听
            $("#queding").click(function (){
                // 获取选中的数据
                if(checktype){
                    // 选中了
                    // 将数据写入到父页面中
                   // checkdata
                    parent.$("#handlerName").val(checkdata.allName);
                    parent.$("#handlerId").val(checkdata.id);
                    // 关闭弹框
                    var index =parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                    parent.layer.close(index);//再执行关闭

                }else{
                    //没有选
                    layer.msg('还没有选择经手人',{time:500,icon:5})
                }



            })


            // 查询表单事件监听
            form.on('submit(*)',function (d){

               d =  d.field;

               // 1.再次请求后台 2，再次渲染table
                // table 重载
                table.reload('tableId',{
                    where:{
                        deptName:d.deptName,
                        allName:d.allName
                    }
                })



            })


            //第一个实例
            table.render({
                elem: '#demo'
                ,height: 312
                ,url: '/hander/getPage' //数据接口 默认携带page limit
                ,id:'tableId'
                ,page:{
                     limit:5,
                     limits:[1,2,3,4],
                     layout:['count','prev','page','next','limit'],
                     groups:3
                }
                ,cols: [[ //表头
                    {type:'radio'},
                    {field: 'id', title: 'ID'}
                    ,{field: 'allName', title: '用户名',}
                    ,{field: 'deptName', title: '性别',}

                ]]
            });

        });
    </script>

</body>
</html>